package com.harmonk.firstscene.db.repository

import com.harmonk.firstscene.db.dao.EventNoteDao
import com.harmonk.firstscene.db.dao.PersonDao
import com.harmonk.firstscene.db.dao.TrafficEventDao
import com.harmonk.firstscene.db.dao.VehicleDao
import com.harmonk.firstscene.db.entity.EventWithAll
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine

class EventWithAllRepository(
    private val trafficEventDao: TrafficEventDao,
    private val vehicleDao: VehicleDao,
    private val personDao: PersonDao,
    private val eventNoteDao: EventNoteDao
) {
    
    fun getEventWithAll(eventId: Long): Flow<EventWithAll> =
        combine(
            trafficEventDao.getTrafficEvent(eventId),
            vehicleDao.getVehiclesByEventId(eventId),
            personDao.getPersonsByEventId(eventId),
            eventNoteDao.getTrafficNotesByEventId(eventId)
        ) { event, vehicles, persons, notes ->
            EventWithAll(
                trafficEvent = event,
                vehicles = vehicles,
                persons = persons,
                eventNotes = notes
            )
        }

}